package com.sjms._09_结构_享元模式;

import java.util.HashMap;

public class CacheFactory {

    private static final HashMap<String, Cache> CACHE = new HashMap<>();

    public static Cache getCache(String type) {
        Cache cache = CACHE.get("type");

        if (cache == null) {
            switch (type) {
                case "local":
                    cache = new LocalCache();
                    CACHE.put(type, cache);
                    break;
                case "redis":
                    cache = new RedisCache();
                    CACHE.put(type, cache);
                    break;
                default:
                    throw new RuntimeException("操作失败，不存在此类型 type=" + type);
            }
        }
        return cache;
    }

}
